<template>
   <div>
    <el-dialog title="编辑会员" :visible.sync="props.isShow" :before-close="cancel" center>
      <el-form :model="memberForm" ref="memberRef" :rules="rules">
        <el-form-item prop="phone" label="手机号" :label-width="formLabelWidth">
          <el-input v-model="memberForm.phone" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item prop="nickname" label="昵称" :label-width="formLabelWidth">
          <el-input v-model="memberForm.nickname" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="密码" :label-width="formLabelWidth">
          <el-input v-model="memberForm.password" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="状态" :label-width="formLabelWidth">
          <el-tooltip :content="'Switch value: ' + value" placement="top">
            <el-switch
              v-model="memberForm.status"
              active-color="#13ce66"
              inactive-color="#ff4949"
              :active-value="1"
              :inactive-value="2"
            >
            </el-switch>
          </el-tooltip>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="add">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script lang="ts" setup>
const formLabelWidth = "140px";
import { ElMessage } from "element-plus";
import { defineProps, defineEmits, ref, reactive } from "vue";
import type { FormInstance, FormRules } from "element-plus";
import { menuadd, menuinfo, menuedit } from "../../request/api";
import { useStore } from "vuex";
let store = useStore();
const value = ref("1");
let props = defineProps({
  isShow: Boolean,
  isAdd: Boolean,
});

// 调用子传父的事件触发
let emit = defineEmits(["cancel"]);
let menuRef = ref<FormInstance>();

// 数据回显
const lookup = async (id: number) => {
  //   let result: any = await menuinfo({ id });
  //   // console.log(result);
  //   if (result.code == 200) {
  //     menuForm.value = result.list;
  //     // 修改的时候需要id
  //     menuForm.value.id = id;
  //   }
};
// 封装一个确定事件
const confirm = async (formEl: FormInstance | undefined) => {
  //   console.log(menuForm.value, "表单对象");
  if (!formEl) return;
  await formEl.validate((val) => {
    if (val) {
      if (props.isAdd) {
        // menuadd(menuForm.value).then((res) => {
        //   // console.log(res);
        //   if (res.code == 200) {
        //     ElMessage({
        //       showClose: true,
        //       message: res.msg,
        //       type: "success",
        //     });
        //     cancel();
        //   } else {
        //     ElMessage({
        //       showClose: true,
        //       message: res.msg,
        //       type: "error",
        //     });
        //   }
        //   store.dispatch("menu/getMenuActions");
        // });
      } else {
        // menuedit(menuForm.value).then((res) => {
        //   // console.log(res);
        //   if (res.code == 200) {
        //     ElMessage({
        //       showClose: true,
        //       message: res.msg,
        //       type: "success",
        //     });
        //     cancel();
        //   } else {
        //     ElMessage({
        //       showClose: true,
        //       message: res.msg,
        //       type: "error",
        //     });
        //   }
        //   store.dispatch("menu/getMenuActions");
        // });
      }
    }
  });
};
// 可以通过defineExpose 编译器宏来显示指定在 <script setup> 组件中要暴露出去的属性
defineExpose({
  lookup,
});
</script>

<style lang="less" scoped></style>
